package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.OhFeiGoodsAreaServerDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.OhFeiGoodsAreaServerInfo;

/**
 * 
 * @description 殴飞产品区服DAO
 * @author Wangxuegang
 * @date 2012-9-29
 * 
 */
@Repository("ohFeiGoodsAreaServerDAO")
public class OhFeiGoodsAreaServerDAOImpl extends
		SuperDAO<OhFeiGoodsAreaServerInfo> implements OhFeiGoodsAreaServerDAO {

	/**
	 * 产品品牌分页查询
	 * 
	 * @param info
	 * @return
	 */
	@Override
	public Pagination<OhFeiGoodsAreaServerInfo> queryPaginationList(
			OhFeiGoodsAreaServerInfo info) {
		Pagination<OhFeiGoodsAreaServerInfo> paginationList = null;
		Integer rowCount = queryRowCount(info);

		info.calculate();
		List<OhFeiGoodsAreaServerInfo> list = queryResultList(info);
		paginationList = this.queryPagination(rowCount, list, info);

		return paginationList;

	}

	/**
	 * 查询记录总数
	 * 
	 * @param pageInruire
	 * @return
	 */
	private Integer queryRowCount(OhFeiGoodsAreaServerInfo info) {
		Integer rowCount = 0;
		rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.OhFeiGoodsAreaServerMapper.queryRowCount", info);

		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param goodsManageInfo
	 * @return
	 */
	private List<OhFeiGoodsAreaServerInfo> queryResultList(
			OhFeiGoodsAreaServerInfo info) {
		List<OhFeiGoodsAreaServerInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.OhFeiGoodsAreaServerMapper.queryResultList", info);

		return list;
	}

	/**
	 * 记录新增
	 * 
	 * @param info
	 */
	@Override
	public void insert(OhFeiGoodsAreaServerInfo info) {
		this.getSqlSession().insert(
				"mybatis.xml.OhFeiGoodsAreaServerMapper.insert", info);

	}

	/**
	 * 根据sx，查询单条记录
	 * 
	 * @param sx
	 * @return
	 */
	@Override
	public OhFeiGoodsAreaServerInfo queryBySx(String sx) {
		OhFeiGoodsAreaServerInfo info = null;
		info = this.getSqlSession().selectOne(
				"mybatis.xml.OhFeiGoodsAreaServerMapper.queryBySx", sx);

		return info;
	}

	/**
	 * 记录更新
	 * 
	 * @param info
	 */
	@Override
	public void update(OhFeiGoodsAreaServerInfo info) {
		this.getSqlSession().update(
				"mybatis.xml.OhFeiGoodsAreaServerMapper.update", info);
	}

	/**
	 * 根据商品Id，查询区服表（返回结果可能多条记录）
	 * 
	 * @param goodsId
	 * @return
	 */
	@Override
	public List<OhFeiGoodsAreaServerInfo> queryByGoodsId(String goodsId) {
		List<OhFeiGoodsAreaServerInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.OhFeiGoodsAreaServerMapper.queryByGoodsId",
				goodsId);

		return list;
	}

	@Override
	public List<String> queryAreaNameByGoodsId(String goodsId) {
		List<String> list = this
				.getSqlSession()
				.selectList(
						"mybatis.xml.OhFeiGoodsAreaServerMapper.queryAreaNameByGoodsId",
						goodsId);
		return list;
	}

}
